/**
 * @module  Utils-Storage
 *
 * @description  设置存储.
 *
 * @param    {string}  key
 * @param    {string}  state
 *
 * @returns  {any}
 */
type SetItem = (key: string, state: string) => any

/**
 * @description  获取存储.
 *
 * @param    {string}  key
 *
 * @returns  {any}
 */
type GetItem = (key: string) => any

/**
 * @description  移除存储.
 *
 * @param    {string}  key
 *
 * @returns  {any}
 */
type RemoveItem = (key: string) => any

/**
 * @description  UniStorage的接口类型，继承于Storage.
 *
 * @extends  {Storage}
 *
 * @typedef  {UniStorage}
 *
 * @interface  UniStorage
 */
interface UniStorage extends Storage {
  setItem: SetItem
  getItem: GetItem
  removeItem: RemoveItem
}

/**
 * @description  利用uni的本地存储操作实现uniStorage的设置、获取、移除功能重写.
 *
 * @type  {Storage}
 */
const uniStorage: Storage = {
  /**
   * @function
   *
   * @type  {SetItem}
   */
  setItem(key, state) {
    console.log(key, state)
    return uni.setStorageSync(key, state)
  },
  /**
   * @function
   *
   * @type  {GetItem}
   */
  getItem(key) {
    return uni.getStorageSync(key)
  },
  /**
   * @function
   *
   * @type  {RemoveItem}
   */
  removeItem(key) {
    return uni.removeStorageSync(key)
  },
}

export default uniStorage
